// pages/Live/index.js
Page({
  data: {
    src: "http://wxsnsdy.tc.qq.com/105/20210/snsdyvideodownload?filekey=30280201010421301f0201690402534804102ca905ce620b1241b726bc41dcff44e00204012882540400&bizid=1023&hy=SH&fileparam=302c020101042530230204136ffd93020457e3c4ff02024ef202031e8d7f02030f42400204045a320a0201000400",
    // 弹幕
    barrage: '',
    // 弹幕top值
    scrollTop: 0,
    // 弹幕内容
    barrageData: [{
        name: 'Sam',
        val: 'Hello World',
        active: false
      },
      {
        name: 'Sam',
        val: 'Hello World Hello World Hello World Hello World Hello World Hello World',
        active: false
      },
      {
        name: 'Sam',
        val: 'Hello World',
        active: false
      },
      {
        name: 'Sam',
        val: 'Hello World',
        active: false
      },
      {
        name: '管理管理员',
        val: '欢迎大家',
        active: true
      },
      {
        name: 'Sam',
        val: 'Hello World',
        active: false
      },
      {
        name: 'Sam',
        val: 'Hello World',
        active: false
      },
      {
        name: 'Sam',
        val: 'Hello World',
        active: false
      },
      {
        name: 'Sam',
        val: 'Hello World',
        active: false
      },
    ]
  },

  tapSend() {
    let that = this
    that.data.barrageData.push({
      name: 'Sam',
      val: that.data.barrage,
      active: false
    })
    that.setData({
      barrageData: that.data.barrageData
    })
    wx.createSelectorQuery().select('#message-item').boundingClientRect(function (rect) {
      that.setData({
        scrollTop: rect.top * 3
      }); // 拉到最底部
      that.setData({
        barrage: ''
      })
    }).exec();
  },
})